package com.ridu.project.beshid.controller;

import com.ridu.project.beshid.api.GeneralResponse;
import com.ridu.project.beshid.api.Status;
import com.ridu.project.beshid.entity.UserEntity;
import com.ridu.project.beshid.service.AppealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by Administrator on 2017/2/13.
 */
@Controller
@RequestMapping(value = "appeal",produces = "application/json")
@Slf4j
public class AppealController extends BaseController {

    @Autowired
    private AppealService service;

    @RequestMapping(value = "redirectSys",method = RequestMethod.POST)
    public String redirectSys(){
        return "audit_admin";
    }

    @RequestMapping(value = "toAudit",method = RequestMethod.POST)
    public String toAudit(){
        return "appeal";
    }

    @RequestMapping(value = "getAll")
    @ResponseBody
    public GeneralResponse getContent(@RequestParam int currentPage, @RequestParam int pageSize){
        return service.findAll(currentPage,pageSize);
    }

    @RequestMapping(value = "audit",method = RequestMethod.POST)
    @ResponseBody
    public GeneralResponse audit(@RequestParam Long id, @RequestParam String status){
        return service.audit(id, status);
    }

    @RequestMapping(value = "save",method = RequestMethod.POST)
    @ResponseBody
    public GeneralResponse save(@RequestParam String type, @RequestParam String description){
        GeneralResponse response = new GeneralResponse();
        try{
            UserEntity user = getUser();
            if(user == null){
                throw new Exception("请登录");
            }
            return service.save(type, description, user);
        } catch (Exception e){
            response.setStatus(Status.FAILED);
            response.setMessage(e.getMessage());
        }
        return response;
    }

}

